package com.crm.service.Impl;

import com.crm.mapper.clientMapper;
import com.crm.pojo.client;
import com.crm.pojo.pageBean;
import com.crm.service.clientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class clientServiceImpl implements clientService {
    @Autowired
    private clientMapper clientmapper;


    @Override
    public client selectByCid(Integer cid) {
        return clientmapper.selectByCid(cid);
    }

    @Override
    public boolean add(client client) {
        return clientmapper.add(client);
    }

    @Override
    public boolean updateByCid(client client) {
        return clientmapper.updateByCid(client);//return true;
    }

    @Override
    public boolean deleteByCid(Integer cid) {
        return clientmapper.deleteByCid(cid);
    }

    @Override
    public int deleteByIds(int[] ids) {
        return clientmapper.deleteByIds(ids);
    }

    @Override
    public pageBean<client> selectByPage(Integer uid, Integer currentPage, Integer pageSize) {
        //计算开始索引
        int currentPage1 = (currentPage - 1)*pageSize;

        List<client> clients = clientmapper.selectAllByUid(uid);
        List<client> list = clientmapper.selectByPage(uid, currentPage1, pageSize);

        pageBean pageBean = new pageBean();
        pageBean.setRows(list);
        pageBean.setTotalCount(clients.size());
        return pageBean;
    }
}
